import os
from openai import OpenAI

from tests import config

try:
    client = OpenAI(
        # 若没有配置环境变量，请用阿里云百炼API Key将下行替换为：api_key="sk-xxx",
        api_key=config.modeConfig["api_key"],
        base_url=config.modeConfig["base_url"],
    )

    completion = client.chat.completions.create(
        model=config.modeConfig["model"],
        messages=config.modeConfig["messages"]
    )
    print(completion.choices[0].message.content)
except Exception as e:
    print(f"错误信息：{e}")
    print("请参考文档：https://help.aliyun.com/zh/model-studio/developer-reference/error-code")